package ru.kruzhki.client.ui.searchform;

import ru.kruzhki.client.gwtp.AbstractWidgetPresenter;
import ru.kruzhki.client.place.NameTokens;
import ru.kruzhki.client.ui.searchresults.SearchResultsPresenter;

import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.client.proxy.PlaceRequest;

public class SearchFormPresenter extends AbstractWidgetPresenter<SearchFormPresenter.MyView>  {

	public interface MyViewHandler {
		void onSearchClick();
	}
	
	public interface MyView extends View {
		void setViewHandler(MyViewHandler viewHandler);
	}


	private final PlaceManager placeManager;


	@Inject
	public SearchFormPresenter(final EventBus eventBus, final MyView view, PlaceManager placeManager) {
		super(eventBus, view);
		this.placeManager = placeManager;
	}


	@Override
	protected void onBind() {
		super.onBind();
		getView().setViewHandler(new MyViewHandler(){
			@Override
			public void onSearchClick() {
				PlaceRequest placeRequest = new PlaceRequest(NameTokens.response).with(SearchResultsPresenter.MyParam.SEARCH_TEXT.name().toLowerCase(), "some text");
				placeManager.revealPlace(placeRequest);
			}
		});
	}

	@Override
	protected void onReset() {
		super.onReset();
	}
	

}
